#include<bits/stdc++.h>
#define int long long
#define lowbit(x) (x&(-x))
#define rep(i,l,r) for(int i=(l);i<=(r);++i)
#define IN(x) freopen(#x".in","r",stdin)
#define OUT(x) freopen(#x".out","w",stdout)
template<class T=int>
inline T read(){
    T x=0; char c=0; bool sgn=0;
    for(;!isdigit(c);c=getchar())sgn|=(c=='-');
    for(;isdigit(c);c=getchar())x=(x<<3)+(x<<1)+(c^48);
    return sgn?-x:x;
}
template<class T>
inline void write(T x){
    static char c[45]; unsigned p=0;
    if(x<0)putchar('-'),x=-x;
    do c[++p]=(x%10)^48,x/=10; while(x);
    while(p)putchar(c[p--]);
}
inline void write(char c){putchar(c);}
template<class T,class ...U>
inline void write(T x,U ...t){
    write(x),write(t...);
}
using namespace std;
const int N=2e5+10;
int T,n,a[N],ans;
signed main(){
    IN(color);
    OUT(color);
    scanf("%lld",&T);
    while(T--){
        scanf("%lld",&n);
        rep(i,0,n-1)scanf("%lld",&a[i]);
        ans=0;
        for(int st=0;st<(1<<n);++st){
                int res=0;
            for(int i=0;i<n;++i){
                for(int j=i-1;j>=0;--j){
                    int st1=(st>>j&1),st2=(st>>i&1);
                    if(st1==st2&&a[i]==a[j]){
                        res+=a[i];
                        break;
                    }
                }
            }
            ans=max(ans,res);
        }
        printf("%lld\n",ans);
    }
    return 0;
}
